/*****************************************************************************
 * vlc_connect.c : GTK+ plugin for vlc
 *****************************************************************************/

#include <vlc/vlc.h>
#include <vlc_interface.h>
#include <vlc_playlist.h>

#include "vlc_connect.h"
#include "intf.h"
#include "menubar.h"
#include "dialogs/opendialog.h"
#include "dialogs/seektimedialog.h"
#include "dialogs/helpdialog.h"
#include "dialogs/aboutdialog.h"
#include "gtk_extra/gtk_extra.h"
#include "resources/stock_icons.h"

static intf_thread_t *intf_thread;

void
vlc_connect_init (intf_thread_t *p_intf)
{

  intf_thread = p_intf;

}

intf_thread_t*
vlc_connect_get_intf_thread_pointer (void)
{
  return intf_thread;
}

intf_sys_t*
vlc_connect_get_intf_sys_pointer (void)
{

  return (intf_sys_t *)intf_thread->p_sys;

}

playlist_t*
vlc_connect_get_playlist_pointer (void)
{

  return (playlist_t *)intf_thread->p_sys->p_playlist;
  
}

void
play (void)
{

  GtkWidget *image;

  image = gtk_image_new_from_vlc_stock (VLC_STOCK_MEDIA_PAUSE, VLC_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (VLC_INTF_SYS->play_button), image);

  playlist_Play (VLC_PLAYLIST);

}

void
pause (void)
{

  GtkWidget *image;

  image = gtk_image_new_from_vlc_stock (VLC_STOCK_MEDIA_PLAY, VLC_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (VLC_INTF_SYS->play_button), image);
  
  playlist_Pause (VLC_PLAYLIST);

}

void
stop (void)
{

  GtkWidget *image;

  image = gtk_image_new_from_vlc_stock (VLC_STOCK_MEDIA_PLAY, VLC_ICON_SIZE_BUTTON);
  gtk_button_set_image (GTK_BUTTON (VLC_INTF_SYS->play_button), image);

  playlist_Stop (VLC_PLAYLIST);

  /* FIXME */
  //gtk_widget_set_size_request (VLC_INTF_SYS->p_video, 0, 0);
  //gtk_window_resize (GTK_WINDOW (VLC_INTF_SYS->p_window), 1, 1);

}

void
previous (void)
{

  playlist_Prev (VLC_PLAYLIST);

}

void
next (void)
{

    playlist_Next (VLC_PLAYLIST);
}

void
fullscreen (void)
{

  vout_thread_t *p_vout;

  p_vout = (vout_thread_t *)vlc_object_find (VLC_INTF_THREAD, VLC_OBJECT_VOUT, FIND_ANYWHERE);

  if (p_vout)
   {
    var_SetBool (p_vout, "fullscreen", !var_GetBool (p_vout, "fullscreen"));
    vlc_object_release (p_vout);
   }

}

void
show_open_file (void)
{

  GtkWidget *dialog;
  GtkWidget *image;

  dialog = vlc_open_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window), VLC_OPEN_DIALOG_FILE);

  switch (gtk_dialog_run (GTK_DIALOG (dialog)))
   {
    case GTK_RESPONSE_OK:
    
     if (is_file_in_playlist ())
      {
       image = gtk_image_new_from_vlc_stock (VLC_STOCK_MEDIA_PAUSE, VLC_ICON_SIZE_BUTTON);
       gtk_button_set_image (GTK_BUTTON (VLC_INTF_SYS->play_button), image);
      }
     
    break;
    
    case GTK_RESPONSE_CANCEL:
    break;
   }  

  gtk_widget_destroy (dialog);

}

void
show_open_disc (void)
{

  GtkWidget *dialog;
  
  dialog = vlc_open_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window), VLC_OPEN_DIALOG_DISC);

  switch (gtk_dialog_run (GTK_DIALOG (dialog)))
   {
    case GTK_RESPONSE_CANCEL:
    break;
   }  
  gtk_widget_destroy (dialog);

}

void
show_open_network (void)
{

  GtkWidget *dialog;
  
  dialog = vlc_open_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window), VLC_OPEN_DIALOG_NETWORK);
  
  switch (gtk_dialog_run (GTK_DIALOG (dialog)))
   {
    case GTK_RESPONSE_CANCEL:
    break;
   }  
  gtk_widget_destroy (dialog);

}

void
show_open_capture_device (void)
{

  GtkWidget *dialog;
  
  dialog = vlc_open_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window), VLC_OPEN_DIALOG_CAPTURE_DEVICE);
  
  switch (gtk_dialog_run (GTK_DIALOG (dialog)))
   {
    case GTK_RESPONSE_CANCEL:
    break;
   }  
  gtk_widget_destroy (dialog);

}

int
is_playing (void)
{

  int i = FALSE;

  if (VLC_PLAYLIST->p_input)
   {  
    i = (VLC_PLAYLIST->p_input->i_state == PLAYING_S);
   }

  return i;

}

int
is_file_in_playlist (void)
{

  return (VLC_PLAYLIST->current.i_size != 0);

}

void
show_seek_time (void)
{

  GtkWidget *dialog;
  dialog = vlc_seek_time_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window));

  switch (gtk_dialog_run (GTK_DIALOG (dialog)))
   {
    
    case GTK_RESPONSE_CANCEL:
    break;
   }  

  gtk_widget_destroy (dialog);

}

void
show_about (void)
{

  GtkWidget *dialog;
  
  dialog = vlc_about_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window));
  gtk_widget_show (dialog);

}

void
show_help (void)
{

  GtkWidget *dialog;
  dialog = vlc_help_dialog_new (GTK_WINDOW (VLC_INTF_SYS->p_window));
  gtk_widget_show (dialog);

}

void
show_video_menu (void)
{

	gtk_menu_popup (GTK_MENU (vlc_menu_get_popup_menu ()),
	                NULL,
	                NULL,
	                NULL,
	                NULL,
			            0,
			            gtk_get_current_event_time ());
			            
}

void
quit (void)
{

  gtk_widget_destroy (VLC_INTF_SYS->p_window);  

}


